package bibliotheque.transaction;

import java.io.Serializable;

public class TransactionId implements Serializable, Comparable{
    
    private String client;
    private int num;
    
    public TransactionId(String client, int num) {
        this.client = client;
        this.num = num;
    }
    
    public String GetClient(){
        return this.client;
    }
    
    public int GetNum(){
        return this.num;
    }
    
    public int compareTo(Object obj) throws ClassCastException {
        if(!(obj instanceof TransactionId)) throw new ClassCastException();
        TransactionId id = (TransactionId)obj;
        if(this.client.equals(id.GetClient())) return(new Integer(this.GetNum()).compareTo(new Integer(id.GetNum())));
        else return(this.client.compareTo(id.GetClient()));
    }
    
    public boolean equals(Object obj) {
        if (!(obj instanceof TransactionId))
            return false;
        TransactionId id = (TransactionId)obj;
        return (this.client.equals(id.client) && this.num == id.GetNum());
    }
    
    public int hashCode() {
        return(this.client.hashCode()+this.num) % Integer.MAX_VALUE;
    }
}
